package untity

import (
	"log"
	"os"
	"os/exec"
	"path/filepath"
)

type ProUntity struct {
}

func (p *ProUntity) GetCurrentPath() string {
	path, err := os.Executable()
	if err != nil {
		log.Println(err)
	}
	dir := filepath.Dir(path)

	dir = "/home/yh/OjProject/HyJudgeServe"
	return dir
}

//创建一个代码文件 因为大部分编译器无法执行对代码进行编译
func (p *ProUntity) CreateCodeFiles(Code string, FileName string) error {
	f, err := os.Create("./File/" + FileName)
	if err != nil {
		return err
	}
	f.Write([]byte(Code))

	return nil
}

//创建一个进程获取一个输出流
func (p *ProUntity) StartProcess(ProcessPath string, Arge []string) string {
	Cmd := exec.Command(ProcessPath, Arge...)
	da, _ := Cmd.CombinedOutput()
	Cmd.Wait()
	return string(da)
}
